package pers.billy.test;

import pers.billy.test.memory.HeapOutMemoryErrorEntity;
import pers.billy.test.memory.StackOutMemoryErrorThead;
import pers.billy.test.memory.StackOverFlowErrorEntity;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * 内存管理测试
 *
 * @author billymac
 * @version 1.0
 * @date 17/6/16  下午6:07
 * @since JDK1.8
 */
public class Main {

    public static void main(String[] args) {
        //StackOverFlowError
//        StackOverFlowErrorEntity entity = new StackOverFlowErrorEntity();
//        entity.test();
//        entity.test(1);
//        entity.test(1,1);
//        entity.test(1,2,3);

        //heapOutMemoryError
//        List<HeapOutMemoryErrorEntity> heaps = new ArrayList<HeapOutMemoryErrorEntity>();
//        while(true) {
//            heaps.add(new HeapOutMemoryErrorEntity());
//        }


        //stackOutMemoryError
//        while(true)
//            new StackOutMemoryErrorThead().start();

        //permGen outMemoryError
//        List<String>  permGens = new ArrayList<String>();
//        int size = 0;
//        while(true) {
//            permGens.add("Hello world!" + size);
//            size++;
//        }


//        System.out.println(Runtime.getRuntime().totalMemory() / 1000000);
//        System.out.println(Runtime.getRuntime().freeMemory() / 1000000);
//        System.out.println(Runtime.getRuntime().maxMemory() / 1000000);

        long tmp = 0;
//        synchronized (Main.class) {
//            tmp++;
//        }
//        Lock lock = new ReentrantLock(false);
//        lock.lock();
//        tmp++;
//        lock.unlock();
//        System.out.println(tmp);

        Object oA = new Main();
        Object oB = new Main();

        Object oC = oA;
        Object od = oB;

        oA = null;
        oB = null;
        System.gc();

    }
}
